package com.cs.study.homework._0311.TestTCP2;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //1. 创建服务端的socket对象(ServerSocket)
        ServerSocket serverSocket = new ServerSocket(4567);
        //2. 通过accept建立连接, 得到socket对象
        Socket socket = serverSocket.accept();
        //3. 从socket中得到输入输出流
        InputStream in = socket.getInputStream();

        //4. 利用输入输出流进行读写操作
        byte[] bytes = new byte[1024];
        int readCount = in.read(bytes);
        String s = bytes.toString();

        System.out.println(s);
        in.close();
        socket.close();

    }
}
